<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> 
<meta name="keywords" content="carousel, jquery, responsive, fluid, elastic, resize, thumbnail, slider" />
<meta name="author" content="Codrops" />
<title>微评说客</title>
<link rel="stylesheet" type="text/css" href="/Public/home/style/public.css">
<link rel="stylesheet" type="text/css" href="/Public/home/style/style.css">
<link rel="stylesheet" type="text/css" href="/Public/home/style/font-awesome.css">
<script src="/Public/home/jquery/jquery-1.7.2.min.js"></script>
<style>
	html,body{ background:#f2f2f2;}
</style>
<script type="text/javascript">
function setvalue(name,id){
	
	$("#"+id).val($("#radio_text"+id).val());
	
}


</script>

</head>

<body>
<header class="index-header">
	<h1>问卷调查</h1>
    <a href="javascript:window.history.back();" class="icon-circle-arrow-left kl"></a>
</header>

<section class="tq-c">
	<h1>{$questionnaire.name}</h1>
    <div class="tq-c2">
    	<p>{$questionnaire.description}</p>
        <span></span>
    </div>
    <form id='addForm'  type='post'>
    <div class="tq-content">
    	<ul>
    	<php>$radionum=1;$radiochange=0;$checknum=1;$checkchange=0;$textnum=1;$textchange=0;</php>
    	<volist name="info" id="vo">
    		<li>
   			  <h3>{$i}. {$vo.name} <b>*</b></h3>
    			<div class="tqw">
    			
    			<volist name="vo.options" id="so" key="k">
                	
                	<if condition="($so.type eq 'text')">
                	<p><textarea id="text<php>echo $textnum;</php>" pid={$vo.id}  placeholder="输入您的感想"></textarea></p>
                	<php>$radiochange=0;$textchange=1;</php>
                	<elseif condition="$so.type eq 'radio' " />
                	<p><input type="{$so.type}" name="radio<php>echo $radionum;</php>" value="" id="{$so.id}" pid="{$vo.id}" cid="{$k-1}" isother="0"><span>{$k}. {$so.text}</span></p>
                	<php>$radiochange=1;</php>
                	<elseif condition="$so.type eq 'radio_othertext' " />
                	<p><input type="radio" name="radio<php>echo $radionum;</php>" value=""  id="{$vo.id}{$k-1}" cid="{$k-1}" pid="{$vo.id}" isother="0"><span>{$k}. <textarea onblur="setvalue('radio<php>echo $radionum;</php>',{$vo.id}{$k-1})" id="radio_text{$vo.id}{$k-1}" name="radio_text<php>echo $num;</php>" style="width: 200px;
height: 20px;" cols="1" rows="1" placeholder="其他"></textarea></span></p>
                	<php>$radiochange=1;</php>
                	<elseif condition="$so.type eq 'checkbox_othertext' " />
                	<p><input type="checkbox" name="checkbox<php>echo $checknum;</php>" value="{$k}" pid="{$vo.id}" cid="{$k-1}"  id="{$vo.id}{$k-1}"><span>{$k}. <textarea  onblur="setvalue('radio<php>echo $radionum;</php>',{$vo.id}{$k-1})" id="radio_text{$vo.id}{$k-1}" style="width: 200px;
height: 20px;" cols="1" rows="1" placeholder="其他"></textarea></span></p>
                	<php>$radiochange=0;$checkchange=1;</php>
                	<else />
                	<p><input type="{$so.type}" name="checkbox<php>echo $checknum;</php>" value=""  pid="{$vo.id}" cid="{$k-1}"  id="{$vo.id}{$k-1}"><span>{$k}. {$so.text}</span></p>
                	<php>$radiochange=0;$checkchange=1;</php>
                	</if>
                	
                	</volist>
                	<php>if($radiochange)$radionum++;if($checkchange)$checknum++;$checkchange=0;if($textchange)$textnum++;$textchange=0;</php>
              </div>
    		</li>
    		</volist>
    		
            <li><input type="button" value="提交问卷" class="button" onclick="submitdata()"></li>
    	</ul>
    </div>
    </form>
</section>
<div class="hh"></div>
<nav>
	<ul>
		<li>
        	<a href="index.html" class="n1">
				<p></p>
				<span>首页</span>
			</a>
        </li>
		<li>
        	<a href="questionnaire.html" class="n2">
				<p class="current"></p>
				<span class="current">问卷</span>
			</a>
        </li>
		<li>
        	<a href="Post.html" class="n3">
				<p></p>
				<span>发布</span>
			</a>
        </li>
		<li>
        	<a href="mine.html" class="n4">
				<p></p>
				<span>我的</span>
			</a>
        </li>
	</ul>
</nav>
</body>

<script type="text/javascript">

function submitdata(){
	var datastr="";
	var fuc=checkfill();
	if(fuc){
		datastr=getdata();
		
		addque(datastr);
	 
	}
	
}

function ToUnicode(str) 
{
 return escape(str).replace(/%/g,"\\").toLowerCase();
}

function addque(data){
	 $.post("/home/index/addreply",
			  {
		 		content:data,
		 		id:{$questionnaire.id},
			  },
			  function(data){
				  if(data.type=="2")
					  alert(data.errorMsg);
				  else
					  window.location.href='statistic.html?questionnaireID={$questionnaire.id}';
			  });
	
}
function getdata(){
	var datastr="";
	var pid="";
	   for(var i=1;i<<php>echo $checknum;</php>;i++){
		   var str="";
    $("input[name='checkbox"+i+"']:checkbox").each(function(){ 
 	  
        if($(this).attr("checked")){
     	   pid=$(this).attr("pid");
     	   
     	   if($(this).attr("value"))
            str +=$(this).attr("cid")+":"+ToUnicode ($(this).attr("value"))+",";
            else
         	   str +=$(this).attr("cid")+",";  
           
        }
    })
   
    str=str.substring(0,str.length-1);
   
    str="\""+pid+"\""+":\""+str+"\"";
    
    datastr+=str+",";
	   }
	  for(var i=1;i<<php>echo $radionum;</php>;i++){
		   var str="";
		   pid="";
	       $("input:radio[name='radio"+i+"']:checked").each(function(){ 
	    	  
	           if($(this).attr("checked")){
	        	   pid=$(this).attr("pid");
	        	   if($(this).attr("value"))
	               str +=$(this).attr("cid")+":"+ToUnicode ($(this).attr("value"))+",";
	               else
	            	   str +=$(this).attr("cid")+",";  
	              
	           }
	       })
	     
	       str=str.substring(0,str.length-1);
	      
	       str="\""+pid+"\""+":\""+str+"\"";
	       datastr+=str+",";
	      
		   }
	   
	   for(var i=1;i<<php>echo $textnum;</php>;i++){
		   var str="";
	      str=$("#text"+i).val();
	      pid=$("#text"+i).attr("pid");
	       
	       str="\""+pid+"\""+":\""+ToUnicode(str)+"\"";
	       datastr+=str+",";
		   }
	   datastr=datastr.substring(0,datastr.length-1);
	   return "{"+datastr+"}";
}
function checkfill(){
	var isfilled=false;
	for(var i=1;i<<php>echo $radionum;</php>;i++){
	if($(':radio[name=radio'+i+']:checked').length>0) {
		isfilled=true;
	}
	else
		isfilled=false;
	}
	
	for(var i=1;i<<php>echo $checknum;</php>;i++){
		
		if($("input:checkbox[name='checkbox"+i+"']:checked").length>0){
			isfilled=isfilled && true;
		}
		else
			isfilled=false;
	}
	
	for(var i=1;i<<php>echo $textnum;</php>;i++){
		
		if(!$("#text"+i).val()==''){
			isfilled=isfilled && true;
		}
		else
			isfilled=false;
	}
	
	if(!isfilled){
	alert("请将调查问卷填写完整！");
	return false;
	}
	else
		return true;
	
	
}

</script>
</html>
